home *** CD-ROM | disk | FTP | other *** search
/ How to Get Online 1996 Spring / HOW2GON.ISO / mac / Servers & CGI / CmmCGI / HTMLCOPY.LIB < prev    next >
Encoding:
Text File  |  1996-02-07  |  1.1 KB  |  40 lines  |  [TEXT/ttxt]

  1. // htmlcopy.lib - Useful routine for CMMCGI.EXE to copy from an existing html
  2. // ver.1          file and make changes to it.
  3. //
  4. // *** ReadFile() - Read file into a buffer
  5. // SYNTAX: buf ReadFile(FileSpec)
  6. // WHERE: FileSpec: specification for file, probably an HTML file
  7. // RETURN: return string as read from file, or NULL if failed
  8. //
  9. // *** StrReplace()- String Replace
  10. // SYNTAX: bool StrReplace(Str,Find,Replace)
  11. // WHERE: Str: String to search in
  12. //        Find: string to search for (case-sensitive)
  13. //        Replace: string to replace it with
  14. // RETURN: Pointer beyond string if found and replaced, else NULL
  15. //
  16. //
  17.  
  18. ReadFile(pFileSpec)
  19. {
  20.    if ( !(fp = fopen(pFileSpec,"rb")) )
  21.       return NULL;
  22.    lTotalLen = 0;
  23.    lBuf = "";
  24.    while ( 0 < (lLen=fread(lBuf+lTotalLen,20000,fp)) )
  25.       lTotalLen += lLen;
  26.    fclose(fp);
  27.    SetArraySpan(lBuf,lTotalLen); // don't waste space
  28.    return lBuf;
  29. }
  30.  
  31. StrReplace(pStr,pFind,pReplace)
  32. {
  33.    if ( !(lFind = strstr(pStr,pFind)) )
  34.       return NULL;
  35.    lRepLen = strlen(pReplace);
  36.    strcpy(lRet=lFind+lRepLen,lFind+strlen(pFind));
  37.    memcpy(lFind,pReplace,lRepLen);
  38.    return lRet;
  39. }
  40.